faApp.controller('MessageListCtrl', ['$scope','MessageService','exportService','$location','$controller','$route','$routeParams','$filter',
function($scope,MessageService,exportService,$location,$controller,$route,$routeParams,$filter) {
  $controller('BaseListCtrl', {$scope: $scope});

  $scope.message = {};
  $scope.list = [];
 
  $scope.addOrEdit = "编辑";

  $scope.$watch('config',function(){
    if ($scope.watchIsChange()){
      MessageService.messageList($scope.config).then(function(json){
        $scope.list = json.list;
        //$scope.pager = json.pager;
        $scope.loading = false;
      }); 
    }
  },true);

  $scope.isEdit = {};
  $scope.messageContent = {};
  $scope.messageType = {};
  $scope.messageRemark = {};
  // 显示编辑框
  $scope.toUpdate = function(id){
    $($scope.list).each(function(i){
      $scope.isEdit[$scope.list[i]['id']] = false;
    });

    $scope.isEdit[id] = true;
  };
  // 保存编辑内容
  $scope.updateContent = function(id){
    //if($scope.messageContent[id] != undefined && $scope.messageContent[id].length > 0){
    if($scope.messageContent[id] != undefined && $scope.messageContent[id].length > 500){
      alert("内容最多500个字符！");
      return;
    }
    $scope.message.id = id;
    $scope.message.smsType = $scope.messageType[id];
    $scope.message.smsContent = $scope.messageContent[id];
    $scope.message.smsRemark = $scope.messageRemark[id];

    MessageService.messageEdit($scope.message).then(function(json){
      if (json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $scope.alertNextPage("修改成功！");
        $route.reload();
      }
    });
    // }else{
    //   alert("内容不能为空！");
    //   return;
    // }
    //$scope.isEdit[id] = false;
  };
}
]);